import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner cin = new Scanner(System.in);
        for(int i=1;i<=7;i++){
            int a = cin.nextInt();
            int b = cin.nextInt();
            if(a+b>8){
                System.out.println(i);
                return;
            }
        }
        System.out.println(0);
        cin.close();
    }
}